import {get,postForm,postJSON} from './request'

/**
 * 实现几个例子，完成get、post-form、post-json测试
 * 这里统一放置所有的web请求
 */

export const sayHello = (param: object)=>{
    let url = '/person/name?'
    Object.keys(param).forEach((key: any) => {
        url += key + '=' + param[key] + '&'
    })
    url = url.substring(0,url.length-1)
    return get(url)
}

export const postname = (data: object)=>{
   let url = '/person/postname?'
   return postForm(url,data)
}

export const newname = (data: object)=>{
   let url = '/person/newname?'
   return postJSON(url,data)
}

/**
 * 模拟从web请求后获取到的路由结构--这里的路由都需要放在/home下做嵌套子路由,为了适用element的容器布局
 */
export const menu = ()=>{
    let menu = [
        {
            title: '用户管理',
            icon:  'Avatar',
            index: 1,
            childs: [
                {
                    title: 'SVIP用户',
                    path: '/svip',
                    name: 'svip',
                    component: 'svip' 
                },
                {
                    title: 'VIP用户',
                    path: '/vip',
                    name: 'vip',
                    component: 'vip' 
                },
                {
                    title: '普通用户',
                    path: '/normaluser',
                    name: 'normaluser',
                    component: 'normal' 
                },
                {
                    title: '游客',
                    path: '/guest',
                    name: 'guest',
                    component: 'guest' 
                }
            ]
        },
        {
            title: '地域管理',
            icon: 'Menu',
            childs: [
                {
                    title: '浙江省',
                    path: '/zhej',
                    name: 'zhej',
                    component: 'guest'
                },
                {
                    title: '山西省',
                    path: '/shanxi',
                    name: 'shanxi',
                    component: 'guest'
                },
                {
                    title: '湖北省',
                    path: '/hubei',
                    name: 'hubei',
                    component: 'guest'
                },
                {
                    title: '湖南省',
                    path: '/hunan',
                    name: 'hunan',
                    component: 'guest'
                }
            ]
        },
        {
            title: '版本管理',
            icon: 'Warning',
            path: '/version',
            name: 'version',
            component: 'version'
        }
    ]
    return menu;
}

/**
 * 模拟动态更新一个同级路由
 * @returns 
 */
export const about = ()=>({path: '/about',name:'about',component: 'AboutView'})